<template>
  <dialog-editor ref="dialog"></dialog-editor>
</template>

<script>
import DialogEditor from '@/components/DialogEditor'
import dialogMixins from '@/utils/commonDialogMixins'

export default {
  mixins: [dialogMixins],
  components: {DialogEditor},
  data() {
    return {
      dataFormConfig: {
        id: {
          hidden: true
        },
        clientName: {
          label: '客户名称',
          placeholder: '请输入客户名称'
        },

        clientCode:{
          label: '客户编码',
          placeholder: '客户编码'
        },
        clientType: {
          label: '客户类型',
          type: 'radio',
          radioBorder: false,
          radioList: [
            {text: '私人', label: 1},
            {text: '公海', label: 99}
          ],
          default: 1
        },
        exhibitionName:{
          label: '展会',
          reply: () => this.R.equals(99, this.dataForm['clientType']),
        },
        companyName:{
          label: '公司名称',
          reply: () => this.R.equals(99, this.dataForm['clientType']),

        },
        position:{
          label: '职位',
          reply: () => this.R.equals(99, this.dataForm['clientType']),

        },
        country:{
          label: '国家/编号',
          reply: () => this.R.equals(99, this.dataForm['clientType']),

        },
        lastUpdateTime:{
          label: '最近一次联系',
          type: 'date',
          reply: () => this.R.equals(99, this.dataForm['clientType']),

        },
        phoneNumber:{
          label: '联系方式',
        },
        respondInfo:{
          label: '回复情况',
          inputType: 'textarea',
          reply: () => this.R.equals(99, this.dataForm['clientType']),

        },
        // sysRegionId:{
        //   label: '客户区域',
        //   placeholder: '客户地址',
        //   type: 'list',
        //   list: []
        // },
        addressDetail: {
          label: '客户详细地址',
          placeholder: '客户详细地址',
        },
        contactName: {
          label: '联系人',
          placeholder: '请输入联系人'
        },
        telephoneNumber: {
          label: '手机号',
          placeholder: '请输入手机号'
        },
        // creditManager: {
        //   label: '是否信用管理',
        //   placeholder: '请输入手机号',
        //   type: 'radio',
        //   radioBorder: false,
        //   radioList: [
        //     {text: '否', label: 0},
        //     {text: '是', label: 1}
        //   ],
        //   default: 0
        // },
        collectionTerms: {
          label: '收款条件',
          type: 'radio',
          radioBorder: false,
          radioList: [
            {text: '现金', label: 0},
            {text: '单月结', label: 1},
            {text: '双月结', label: 2},
            {text: '三月结', label: 3},
          ],
          default: 1
        },
        deliveryModel: {
          label: '发货方式',
          placeholder: '请输入发货方式'
        },
        unitPrice: {
          label: '单价（元/吨）',
          placeholder: '请输入单价（元/吨）',
          type: 'number'
        },
        attritionRate: {
          label: '损耗',
          placeholder: '请输入损耗',
          type: 'number',
          max: 100000
        },
        remark: {
          label: '备注',
          inputType: 'textarea',
          placeholder: '请输入备注'
        },
        status: {
          label: '状态',
          type: 'switch',
          activeValue: 1,
          inactiveValue: 0,
          default: 1
        }
      }
    }
  },
  methods: {
    init(id,property, cb) {
      this.dataForm.id = id || 0
      this.initSysRegionInfoList()

      this.$refs.dialog.initDialog({
        dataForm: this.dataForm,
        config: this.dataFormConfig,
        dataRule: this.getNeedDataRule('clientName', 'status'),
        initApi: 'clientApi/clientInfoInfo',
        saveApi: 'clientApi/saveClientInfo',
        updateApi: 'clientApi/updateClientInfo',
        objectName: 'clientInfo',
        submitCallback: cb
      })
      this.$nextTick(() => {
        if (!this.R.isNil(property)) {
          Object.keys(property).forEach((key) => {
            this.dataForm[key] = property[key]
          })
        }
      })
    }
  }
}
</script>
